package com.ilxqx.framework.system.entity;

import lombok.Data;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.*;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 系统菜单实体类
 * @author venus
 */
@Entity(name = "sys_menu")
@Data
@DynamicInsert
@DynamicUpdate
public class SysMenu implements Serializable {

    private static final long serialVersionUID = 6169955181737790682L;

    /**
     * 菜单主键
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long menuId;

    /**
     * 父级菜单主键
     */
    private Long parentMenuId;

    /**
     * 菜单组件
     */
    private String component;

    @Embedded
    private Meta meta;

    /**
     * 菜单路径
     */
    private String path;

    /**
     * 重定向路径
     */
    private String redirect;

    /**
     * 是否隐藏
     */
    private Boolean hidden;

    /**
     * 是否一直显示
     */
    private Boolean alwaysShow;

    /**
     * 菜单排序
     */
    private Integer sequence;

    /**
     * 菜单备注
     */
    private String remark;

    /**
     * 操作用户主键
     */
    private Long operationUserId;

    /**
     * 操作用户姓名
     */
    private String operationUserName;

    /**
     * 创建时间
     */
    private LocalDateTime createTime;

    /**
     * 更新时间
     */
    private LocalDateTime updateTime;

    @Data
    @Embeddable
    public static class Meta {

        /**
         * 菜单标题
         */
        private String title;

        /**
         * 菜单图标
         */
        private String icon;

        /**
         * 是否不缓存
         */
        private Boolean noCache;

        /**
         * 允许的角色
         */
        @Transient
        private List<String> roles;

    }

    /**
     * 子菜单
     */
    @Column
    @OneToMany(cascade = CascadeType.REMOVE, fetch = FetchType.EAGER, orphanRemoval = true)
    @JoinColumn(name = "parentMenuId")
    private List<SysMenu> children;

}